<?php
class Webmix_Widget_FavouriteMusicController extends Engine_Content_Widget_Abstract
{
  public function indexAction()
  {
    // Don't render this if not authorized
    $this->view->viewer = $viewer = Engine_Api::_()->user()->getViewer();
    if( !Engine_Api::_()->core()->hasSubject() ) {
      return $this->setNoRender();
    }

    // Get subject and check auth
    $this->view->subject = $subject = Engine_Api::_()->core()->getSubject('user');
    if( !$subject->authorization()->isAllowed($viewer, 'view') ) {
      return $this->setNoRender();
    }

    $subject = Engine_Api::_()->core()->getSubject();

    $webmixTable = Engine_Api::_()->getDbtable('webmixes','webmix');
    $webmix = $webmixTable->fetchRow($webmixTable->select()->where('owner_id = ?', $subject->getIdentity())->where('content_type = ?', Webmix_Api_Core::WEBMIX_CONTENT_TYPE_MUSIC) );
    if(!$webmix) return $this->setNoRender();
    $blockTable = Engine_Api::_()->getDbtable('blocks','webmix');
    $this->view->blocks = $blocks = $blockTable->getBlocks($webmix->getIdentity());
    if(count($blocks) < 1) return $this->setNoRender();
  }
}